<?php
/**
 * 用户导出
 * User: cxm
 * Date: 2020/2/10
 * Time: 9:50
 */
namespace App\Excel;

use EasyWeChat\Kernel\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;

class UserExport implements FromCollection
{
    /**
     * 导出数据
     * @var array
     */
    protected $data=array();

    public function __construct($data){
        $this->data = $data;
    }

    //数组转集合
    public function collection()
    {
        return new Collection($this->createData());
    }
    //业务代码
    public function createData()
    {
        $data[] = ["用户名称","手机"];
        foreach ( $this->data as $key=>$item) {
            $data[] = [
                $item['name'],
                $item['mobile']
            ];
        }
        return $data;
    }
}